#include"udpserver.hpp"
#include"route.hpp"
#include"threadpool.hpp"

using task_t =  std::function<void()>;

int main(int argc,char* argv[])
{
    if(argc != 2)
    {   
        std::cerr << "usage:" << argv[0] << " port"<<std::endl;
        exit(3);
    }
    Route r;
    ThreadPool<task_t>* tp = ThreadPool<task_t>::GetTP();
    std::unique_ptr<UdpServer> server = std::make_unique<UdpServer>(std::stoi(argv[1]),[&r,tp](int sockfd,const std::string& message,const InetAddr& client)->void 
    {
        task_t task = bind(&Route::MessageRoute,&r,sockfd,message,client);
        tp->Push(task);
    });
    server->Init();
    server->Start();
    

    return 0;
}